package com.windoent.yugioh.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

import com.windoent.yugioh.R;

/**
 * author : robert
 * date   : 2021/7/15 17:33
 * desc   :加载进度Dialog
 */
public class LoadingDialog extends Dialog {
    public LoadingDialog(Context context, String strMessage) {
        this(context, R.style.LoadingDialogStyle, strMessage);
    }

    public LoadingDialog(Context context, int theme, String strMessage) {
        super(context, theme);
        this.setContentView(R.layout.dialog_loading_layout);
        this.getWindow().getAttributes().gravity = Gravity.CENTER;
        setCancelable(false);// 是否可以按“返回键”消失
        setCanceledOnTouchOutside(false);// 点击加载框以外的区域
        TextView tvMsg = (TextView) this.findViewById(R.id.tv_loadingmsg);
        if (tvMsg != null) {
            tvMsg.setText(strMessage);
        }
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if (!hasFocus) {
            dismiss();
        }
    }
}
